package game.module.user.dao;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import game.module.turntables.bean.TurntableBean;
import game.module.user.bean.Activity_stateBean;


public class ActivitystateCache {
private static Logger logger = LoggerFactory.getLogger(ActivitystateCache.class);
	
	static class SingletonHolder {
		static ActivitystateCache instance = new ActivitystateCache();
	}

	public static ActivitystateCache getInstance() {
		return SingletonHolder.instance;
	}
	
	public Map<Integer,Activity_stateBean> ActivityCacheAll = new ConcurrentHashMap<Integer,Activity_stateBean>();
	
	public void loadFromDB(int playerId) {
		if(ActivityCacheAll.containsKey(playerId)) {
			return;
		}
		Activity_stateBean abean = Activity_stateDao.getInstance().getActivityById(playerId);
		if(abean != null) {
			ActivityCacheAll.put(playerId, abean);
		}
		logger.info("playerId={} load activity",playerId);
	}
	
	public void remove(int playerId ) {
		ActivityCacheAll.remove(playerId);
	}
	
	public void addActivitystate(Activity_stateBean bean) {
		if(bean != null) {
			ActivityCacheAll.put(bean.getPlayerId(), bean);
		}
	}
	
	public Activity_stateBean getActivitystate(int playerId) {
		return ActivityCacheAll.get(playerId);
	}
}
